package com.icinfo.cloud.provider.punish.common.log.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.common.log.dto.SysLogQueryDto;
import com.icinfo.cloud.provider.punish.common.log.model.SysLog;
import com.icinfo.cloud.provider.punish.common.log.service.ISysLogService;
import com.icinfo.cloud.provider.punish.common.log.vo.SysLogQueryVO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import com.icinfo.framework.tools.utils.WebUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhoulx
 * @date 2023/5/9
 */
@Slf4j
@RestController
@RequestMapping("/punish/log")
public class SysLogController extends BaseController {

    @Autowired
    private ISysLogService sysLogService;

    /**
     * 保存日志
     * @param request
     * @param sysLog
     * @return
     */
    @PostMapping("/save")
    public Result<String> save(HttpServletRequest request, @RequestBody SysLog sysLog) {
        sysLog.setOperatorIp(WebUtils.getIpAddress(request));
        sysLogService.save(sysLog);
        return Result.success("操作成功");
    }

    /**
     * 查询日志
     * @param dto
     * @return
     */
    @PostMapping("/query")
    public Result<PageResponse<SysLogQueryVO>> query(@RequestBody SysLogQueryDto dto) {
        List<SysLogQueryVO> list = sysLogService.query(dto);
        return Result.success("操作成功", new PageResponse<>(list));
    }



}
